var flagName = false;
var flagRealName = false;
var flagPas = false;
var flagPass = false;
/*验证用户名*/
var name, realName, passWord, passWords;
$("#register-username").change(function() {
	name = $("#register-username").val();
	if (name.length < 2 || name.length > 10) {
		$("#register-username").removeClass("form-control is-valid")
		$("#register-username").addClass("form-control is-invalid");
		flagName = false;
	} else {
		$("#register-username").removeClass("form-control is-invalid")
		$("#register-username").addClass("form-control is-valid");
		flagName = true;
	}
})
// 验证真实姓名
$("#register-realname").change(function() {
	realName = $("#register-realname").val();
	if (realName.length < 2 || realName.length > 10) {
		$("#register-realname").removeClass("form-control is-valid")
		$("#register-realname").addClass("form-control is-invalid");
		flagRealName = false;
	} else {
		$("#register-realname").removeClass("form-control is-invalid")
		$("#register-realname").addClass("form-control is-valid");
		flagRealName = true;
	}
})
/*验证密码*/
$("#register-password").change(function() {
	passWord = $("#register-password").val();
	if (passWord.length < 6 || passWord.length > 18) {
		$("#register-password").removeClass("form-control is-valid")
		$("#register-password").addClass("form-control is-invalid");
		flagPas = false;
	} else {
		$("#register-password").removeClass("form-control is-invalid")
		$("#register-password").addClass("form-control is-valid");
		flagPas = true;
	}
})
/*验证确认密码*/
$("#register-passwords").change(function() {
	passWords = $("#register-passwords").val();
	if ((passWord != passWords) || (passWords.length < 6 || passWords.length > 18)) {
		$("#register-passwords").removeClass("form-control is-valid")
		$("#register-passwords").addClass("form-control is-invalid");
		flagPass = false;
	} else {
		$("#register-passwords").removeClass("form-control is-invalid")
		$("#register-passwords").addClass("form-control is-valid");
		flagPass = true;
	}
	fullValidata()
})

$("#regbtn").click(function() {
	if (flagName && flagPas && flagPass) {
		localStorage.setItem("name", name);
		localStorage.setItem("passWord", passWord);
		location = "login.html"
	} else {
		if (!flagName) {
			$("#register-username").addClass("form-control is-invalid");
		}
		if (!flagPas) {
			$("#register-password").addClass("form-control is-invalid");
		}
		if (!flagPass) {
			$("#register-passwords").addClass("form-control is-invalid");
		}
	}
})

function fullValidata() {
	if (flagName && flagRealName && flagPas && flagPass && slideVerify.slideFinishState) {
		$("#regbtn").removeClass("btn btn-default")
		$("#regbtn").addClass("btn btn-primary")
		$('#regbtn').removeAttr("disabled");
	}
}
